package com.bw.finance.controller;


import com.bw.finance.conf.ResponseResult;
import com.bw.finance.eneity.locana.EbankAccountLog;;
import com.bw.finance.service.IEbankAccountLogService;
import com.bw.finance.utils.IdWorker;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zxx
 * @since 2020-08-20
 */
@RestController
//@RequestMapping("/account")
//public class EbankAccountLogController {



@RequestMapping("accountlog")
public class EbankAccountLogController {

    @Autowired
    private IEbankAccountLogService accountLogService;

    @Resource
    private IEbankAccountLogService iEbankAccountLogService;
    //借款时的服务调用
    @PostMapping("/findallmoney/{id}")
    public ResponseResult findallmoney(@PathVariable int id){
        return iEbankAccountLogService.findallmoney(id);
    }
    //提现时的服务调用
    @PostMapping("/totixian")
    public ResponseResult totixian(@RequestBody EbankAccountLog ebankAccountLog){
        return iEbankAccountLogService.totixian(ebankAccountLog);
    }

    /**
     * 充值记录列表
     */
    @PostMapping("/getAccountLogList/{pagenum}/{pagesize}")
    public ResponseResult getAccountLogList(@PathVariable("pagenum") int pagenum, @PathVariable("pagesize") int pagesize, @RequestBody EbankAccountLog ebankAccountLog){
        ResponseResult result = ResponseResult.SUCCESS();
        try {
            result = accountLogService.getAccountLogList(pagenum,pagesize,ebankAccountLog);
        }catch (Exception e){
            e.printStackTrace();
            result.setMessage("查询异常");
            result.setSuccess(false);
        }
        return result;
    }

    @PostMapping("/getAccountLogTixianList/{pagenum}/{pagesize}")
    public ResponseResult getAccountLogTixianList(@PathVariable("pagenum") int pagenum, @PathVariable("pagesize") int pagesize, @RequestBody EbankAccountLog ebankAccountLog){
        ResponseResult result = ResponseResult.SUCCESS();
        try {
            result = accountLogService.getAccountLogTixianList(pagenum,pagesize,ebankAccountLog);
        }catch (Exception e){
            e.printStackTrace();
            result.setMessage("查询异常");
            result.setSuccess(false);
        }
        return result;
    }

    @PostMapping("/TixianShenhe/{id}")
    public ResponseResult getAccountLogTixianList(@PathVariable("id") Long id){
        ResponseResult result = ResponseResult.SUCCESS();
        try {
            EbankAccountLog accountLog = accountLogService.getById(id);
            accountLog.setType(2);
            accountLog.setActionTime(new Date());
            accountLog.setArriveTime(new Date());
            IdWorker idWorker = new IdWorker(0, 0, 0);
            accountLog.setDingdan_code(String.valueOf(idWorker.nextId()));
            accountLogService.saveOrUpdate(accountLog);
            result.setMessage("审核成功!");
            result.setSuccess(true);
        }catch (Exception e){
            e.printStackTrace();
            result.setMessage("查询异常");
            result.setSuccess(false);
        }
        return result;
    }

}
